package asteroids.model.programs.parsing.statements;

import java.util.List;
import java.util.Map;

import be.kuleuven.cs.som.annotate.Basic;

import asteroids.model.Ship;
import asteroids.model.programs.parsing.types.Type;

/**
 * A class of sequences.
 *  
 * @author Thijs Dieltjens - Wim Konings
 * @version 2.0
 */
public class Sequence extends Statement {

	public Sequence(List<Statement> statements,int line, int column){
		super(line,column);
		this.statements = statements;
	}

	@Basic
	public List<Statement> getStatements(){
		return statements;
	}

	private List<Statement> statements;

	@Override
	public void execute(Ship ship) {
		for(Statement s : getStatements()){
			s.execute(ship);
		}
	}

	//Recursive method which makes sure that every sequence in a list of statements is converted to a list of normal statements.
	public List<Statement> getAllIndividualStatements(List<Statement> allStatementsSoFar){
		for(Statement s : getStatements()){
			if(s instanceof Sequence){
				allStatementsSoFar = ((Sequence) s).getAllIndividualStatements(allStatementsSoFar);
			}
			else{
				allStatementsSoFar.add(s);
			}
		}
		return allStatementsSoFar;
	}

	@Override
	public List<String> getTypeCheckErrors(List<String> errors, Map<String, Type> globals) {
		for(Statement s : getStatements()){
			errors=(s.getTypeCheckErrors(errors, globals));
		}
		return errors;
	}

	@Override
	public boolean containsActionStatement(){
		for(Statement s: getStatements()){
			if(s.containsActionStatement()){
				return true;
			}
		}
		return false;
	}
}
